using Max.PH5_2103A.Shopping.TEntityFrame.API;
using Max.PH5_2103A.Shopping.TEntityFrame.DAL;
using Max.PH5_2103A.Shopping.TEntityFrame.IRepository;
using Max.PH5_2103A.Shopping.TEntityFrame.IService;
using Max.PH5_2103A.Shopping.TEntityFrame.Repository;
using Max.PH5_2103A.Shopping.TEntityFrame.Service;
using Microsoft.EntityFrameworkCore;
using NLog.Extensions.Logging;

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.

builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen(x =>
{
    x.IncludeXmlComments(@"obj\Debug\net6.0\Max.PH5_2103A.Shopping.TEntityFrame.API.xml");
});


builder.Services.AddAutoMapper(typeof(AutomapperConfig));

builder.Services.AddDbContext<MyDbContext>(x =>
{
    x.UseSqlServer(builder.Configuration.GetConnectionString("SqlServerConnection"));
});

builder.Logging.AddNLog("NLog.config");


builder.Services.AddTransient<IUnitOfWork, UnitOWork>();
builder.Services.AddTransient<IMemberAddressRepository, MemberAddressRepository>();
builder.Services.AddTransient<IMemberAddressService, MemberAddressService>();

builder.Services.AddTransient<ISKURepository, SKURepository>();
builder.Services.AddTransient<IOrderDetailRepository, OrderDetailRepository>();
builder.Services.AddTransient<IOrderMasterRepository, OrderMasterRepository>();

builder.Services.AddTransient<IOrderMasterService, OrderMasterService>();


var app = builder.Build();

// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
    app.UseSwagger();
    app.UseSwaggerUI();
}

app.UseStaticFiles();
app.UseCors(x =>
{
    x.AllowAnyHeader().AllowCredentials().AllowAnyMethod().SetIsOriginAllowed(_=>true);
});

app.UseAuthorization();

app.MapControllers();

app.Run();
